package com.yntx.usercenter.common.web;

/**
 * Description: API接口错误码接口
 *
 * @author Liziba
 * @version 1.0
 * @date 2022/9/22 3:01 PM
 * @since JDK 1.8
 */
public interface Status {

    /**
     * 状态码
     *
     * @return
     */
    Integer getCode();

    /**
     * 返回信息
     *
     * @return
     */
    String getMessage();

    enum Common implements Status {

        /**
         * 成功
         */
        SUCCESS(200, "Request succeeded"),
        /**
         * 失败
         */
        ERROR(500, "Request failed"),
        /**
         * 默认失败
         */
        DEFAULT_ERROR(500, "Request failed"),
        /**
         * 请求异常
         */
        BAD_REQUEST(400, "Request exception"),
        /**
         * 参数不匹配
         */
        PARAM_NOT_MATCH(400, "Parameters do not match"),
        /**
         * 参数不能为空
         */
        PARAM_NOT_NULL(400, "Parameter cannot be empty"),
        /**
         * 登陆失败
         */
        LOGIN_ERROR(401, "Login failed"),
        /**
         * 暂无权限访问
         */
        ACCESS_ERROR(403, "No permission to access"),
        /**
         * 请求不存在
         */
        REQUEST_NOT_FOUND(404, "Request does not exist"),
        /**
         * 请求方式不支持
         */
        HTTP_BAD_METHOD(405, "Request method is not supported"),
        /**
         * 默认业务异常
         */
        COMMON_ERROR(857, "Common request failed"),
        /**
         * 重复请求
         */
        REPEAT_ERROR(20005, "Repeat request"),
        /**
         * 数据不存在
         */
        NOT_FOUND_ERROR(20006, "Data not exist"),

        /**
         * 运行时异常
         */
        RUNTIME_ERROR(100000, "illegal error, please check request message"),
        /**
         * 不合法错误：参数
         */
        ILLEGAL_PARAM_ERROR(100001, "illegal error, please check param"),
        /**
         * 不合法错误：请求
         */
        ILLEGAL_REQUEST_ERROR(100002, "illegal error, please check request"),
        /**
         * 不合法错误：请求数据
         */
        ILLEGAL_REQUEST_MSG_ERROR(100003, "illegal error, please check request message"),
        ;

        private Integer code;

        private String message;

        Common(Integer code, String message) {
            this.code = code;
            this.message = message;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @Override
        public String getMessage() {
            return message;
        }

        @Override
        public String toString() {
            return String.format("Status:{code: %s, message: %s}", getCode(), getMessage());
        }

    }

}
